package cn.usian.service.impl;

import cn.usian.jyzx.model.commot.RedisCommot;
import cn.usian.jyzx.model.entity.product.Brand;
import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import cn.usian.jyzx.model.vo.h5.ProductItemVo;
import cn.usian.mapper.BrandMapper;
import cn.usian.service.BrandService;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.core.util.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceimpl implements BrandService {
    @Autowired
    BrandMapper brandMapper;
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public Result<List<Brand>> findAll() {
        String brandJson = (String) redisTemplate.boundValueOps(RedisCommot.BRAND).get();
        if (brandJson==null){
            List<Brand> brandList= brandMapper.findAll();
            redisTemplate.boundValueOps(RedisCommot.BRAND).set(JSON.toJSONString(brandList));
            return Result.build(brandList, ResultCodeEnum.SUCCESS);
        }


        return Result.build(JSON.parseArray(brandJson, Brand.class), ResultCodeEnum.SUCCESS);


    }


}
